<!DOCTYPE html>
<html id="zfes_login_page">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title></title>
		<meta name="description" content="User login page" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		
	</head>
	<body>
	  
<form>
	用户名:<input type="text" id="username" value="admin"  name="username"  placeholder="用户名" /><br/>
	密码:<input type="password" id="password" value="admin" name="password"placeholder="密码" /><br/>
	验证码:<input type="text" id="captchaz" value="1111" name="captcha" style="width: 165px;" placeholder="验证码" /><br/>
	<img alt="" id="captcha"  onclick="refreshCaptcher();"   src="">
	<input type="button" onclick="dologin();" value="登录">
</form>


<script src="static/jquery/jquery-2.2.4.min.js"></script>
<script src="static/jquery-md5/jquery.md5.min.js" type="text/javascript" ></script>
<script src="static/jquery-validation/jquery.validate.min.js"></script>
<script src="static/sweetalert/sweetalert.min.js" type="text/javascript" ></script>
<script src="static/zfes/zfes.util.js" type="text/javascript" ></script>
<script src="static/zfes/zfes.ajax.js" type="text/javascript" ></script>
<script src="static/zfes/zfes.core.js" type="text/javascript" ></script>
<script src="static/zfes/zfes.util.js" type="text/javascript" ></script>
<script src="static/zfes/zfes.alert.swal.js" type="text/javascript" ></script>
<script src="static/zfes/zfes.storage.js" type="text/javascript" ></script>
<script src="static/zfes/zfes.permisison.js" type="text/javascript" ></script>

<script type="text/javascript">
		if('ontouchstart' in document.documentElement) document.write("<script src='static/libs/jquery/jquery.mobile.custom.js'>"+"<"+"/script>");
		</script>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
		
			function convertPassword(username,password){
				var salt="zhtframework_94DABGioQOq2tTUO0AXYow";
				return hex_md5(salt+password);
			}
			function refreshCaptcher(){
				$('#captcha').hide().attr('src', 'api/auth/captcha?' + Math.floor(Math.random()*100) ).fadeIn();
			}
			
			function dologin(){
				var username = $.trim($("#username").val());
				var password = $.trim($("#password").val());
				var captcha = $.trim($("#captchaz").val());
				if(username.length < 1){
					$("#error_show").empty();
					$("#error_show").html("<font color=\"red\">请输入用户名</font>");
					return;
				}
				if(password.length < 3){
					//$("#username").empty();
					//$("#password").empty();
					$("#password").val();
					$("#error_show").empty();
					$("#error_show").html("<font color=\"red\">请输入密码</font>");
					$("#password").focus();
					return;
				}
				if(captcha.length <3){
					//$("#username").empty();
					//$("#password").empty();
					$("#captchaz").val();
					$("#error_show").empty();
					$("#error_show").html("<font color=\"red\">请输入验证码</font>");
					$("#captchaz").focus();
					return;
				}
				 password=convertPassword(username,password);
				 console.log("password:"+password);
			    var ajaxUrl = "api/auth/login";
				var param = { "username" : username,"password":password,"captcha":captcha,"loginOrgin":"PC"};
				
				zfesAjax.ajaxTodo(ajaxUrl, param, function(data) {
					if(data.statusCode==200){
						window.location.href="index.html";
						// zfesPermStore.initPerm("auth/loadAuthCodes",{},function(){window.location.href="index.html";});
						//登陆成功，写入权限缓存
						/* PermStore.setPermFromUrl(function(){
							var cs_token=data.data.cs_token;
							sessionStorage.setItem("cs_token",cs_token);
							var url="index.html";
						      
							//zfesUtil.locationWithParams(url,{"cs_token":cs_token});
						}); */
					}else{
						//alertMsg.error(data.message);
						$("#captchaz").empty();
						 refreshCaptcher();
						$("#error_show").html(data.message);
						$("#password").empty();
					}
				});  
			}
			$(function(){
				refreshCaptcher();
			}); 
		</script>
	</body>
</html>
